package com.example.base.filewatch;

import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Slf4j
public class WatchFileUtils {


    private static volatile Map<String,Long>  TIME_MAP=new ConcurrentHashMap<>();

    public static boolean isLoadFile(File file){
        String name=file.getName();
        if(!TIME_MAP.containsKey(name)){
            TIME_MAP.put(name,System.currentTimeMillis());
            //开始加载操作
            return true;
        }else {
            Long time=TIME_MAP.get(name);
            Long current_time=System.currentTimeMillis();
            if(current_time - time > 6000){
                TIME_MAP.put(name,System.currentTimeMillis());
                //开始操作
                return true;
            }
        }
        return false;
    }




}
